#!/usr/bin/perl -w

=for comment
This document is in Pod format.  To read this, use a Pod formatter,
like "perldoc perlpod".

=head1 NAME

extract_tags.pl

=head1 DESCRIPTION

Extract elements and content model from a DTD. Output a CSV file with 
the elements in alphabetical order in column one and the content model 
in column two.  Remove tabs, spaces, returns and newlines from the 
content model.

=head1 USAGE

extract_tags.pl <filename>

=cut

#TODO Capture in-line documentation for particular elements into associative array.

use strict;
use diagnostics;
use Getopt::Std;
use Carp;
local $/;
our ($opt_h);
my (%elements);

getopt('h');
&usage if ( defined $opt_h );

while ( my $string = <> ) {

    while ( $string =~ m/<!ELEMENT\s+(.+?)\s+(.+?)\s*>/gs ) {
        ( my $content_model = $2 ) =~ tr/ \n\r\t//d;
        $elements{$1} = $content_model;
    }
}

foreach my $key ( sort ( keys %elements ) ) {
    print "\"$key\",\"$elements{$key}\"\n";
}

sub usage {
    print "Usage: \n";
    return ();
}
